package com.zhu.service;

import com.zhu.mapper.TypeMapper;
import com.zhu.mapper.UserMapper;
import com.zhu.pojo.Expend;
import com.zhu.pojo.Type;
import com.zhu.pojo.Way;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TypeService {
    @Autowired
    private TypeMapper typeMapper;

    @Autowired
    private UserMapper userMapper;


    public List<Type> typeList(String  username) {
        int userId= userMapper.getUserByName(username).getId(); //获取用户id
        return typeMapper.getAll(userId);
    }

    public Type get(int id) {
        Type type= typeMapper.getById(id);
        return type;
    }

    public boolean save(Type type) {
        int row = typeMapper.add(type);
        if(row > 0) {
            return true;
        }else {
            return false;
        }
    }


    public boolean upd(Type type) {
        int row = typeMapper.update(type);
        if(row > 0) {
            return true;
        }else {
            return false;
        }
    }

    public boolean del(int  id) {
        int row = typeMapper.delete(id);
        if(row > 0) {
            return true;
        }else {
            return false;
        }
    }

    public List<Type> typeListByAdmin() {
        return typeMapper.getAllByAdmin();
    }
}
